package Demo1;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-28
 * Time: 13:55
 */
public class Test {
    public static void main(String[] args) {
        Student student1 = new Student("zhangsan",9);
        Student student2 = new Student("zhangsan",9);

        System.out.println(student1.equals(student2));
        System.out.println(student1.hashCode());
        System.out.println(student2.hashCode());

    }
    public static void mai4n(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",9);
        students[1] = new Student("lisi",13);
        students[2] = new Student("wangwu",11);

        AgeComparator ageComparator = new AgeComparator();
        System.out.println("排序前：" + Arrays.toString(students));
        Arrays.sort(students,ageComparator);
        //根据指定的比较器引发的顺序对指定的对象数组进行排序。
        System.out.println("排序后：" + Arrays.toString(students));

    }
    public static void main3(String[] args) {
        Student student1 = new Student("zhangsan",9);
        Student student2 = new Student("lisi",10);
        AgeComparator ageComparator = new AgeComparator();
        NameComparator nameComparator = new NameComparator();
        int ret = ageComparator.compare(student1,student2);
        int ret1 = nameComparator.compare(student1,student2);

        System.out.println(ret);
        System.out.println(ret1);

    }
    public static void mySort(Comparable[] comparables) {
        /*
        为什么使用Comparable：是为了做到标准统一，只要实现了这个接口，我都可以进行mySort比较
         */
        for (int i = 0; i < comparables.length - 1; i++) {
            for (int j = 0; j < comparables.length- i - 1; j++) {
                Comparable tmp = comparables[j];
                comparables[j] = comparables[j+1];
                comparables[j+1] = tmp;
            }
        }
    }

    public static void main2(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",9);
        students[1] = new Student("lisi",10);
        students[2] = new Student("wangwu",11);
        System.out.println(Arrays.toString(students));
        //mySort(students);
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
    public static void main1(String[] args) {
        Student student1 = new Student("zhangsan",9);
        Student student2 = new Student("lisi",10);
        //System.out.println(student1.age < student2.age);
        //System.out.println(student1 < student2);
        System.out.println(student1.compareTo(student2));

    }
}
